function [grad,im]=getGradient(c1,c2,numcol)
%function [grad,im]=getGradient(c1,c2,numcol)
%
% This function generates a color gradient from color c1 to color c2, using
% numcol as number of elemets of the gradient. As default, numcol is 64.
%
% INPUT:
% - c1: RGB color given as intensity vector of Red Green and Blue spectrum.
% - c2: same as c1. This is the final value of the gradient.
% - numcol: number of colors or elements of the gradient.
%
% OUTPUT:
% - grad: a matrix of numcol*3 elements containing colormap (or gradient).
% - im: a numcol*20*3 RGB image that can be used to display the result. 


if nargin < 3
    numcol=64;
elseif nargin <2
    disp(['at least 2 colors are needed to obtain a gradient.',...
        'Type help getGradient for more info']);
    return;
end
%increment of R,G,B spectrums.
dr=(c2(1)-c1(1))/(numcol-1);
dg=(c2(2)-c1(2))/(numcol-1);
db=(c2(3)-c1(3))/(numcol-1);

grad=zeros(numcol,3);
r=zeros(20,numcol);
g=zeros(20,numcol);
b=zeros(20,numcol);
for j=1:numcol
    grad(j,1)=c1(1)+dr*(j-1);
    grad(j,2)=c1(2)+dg*(j-1);
    grad(j,3)=c1(3)+db*(j-1);
    r(:,j)=grad(j,1);
    g(:,j)=grad(j,2);
    b(:,j)=grad(j,3);
end

im=cat(3,r,g,b);
